﻿using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;

namespace QWManage.Excel
{
    public class CellStyleHelper
    {
        private HSSFWorkbook _workbook;

        private ICellStyle _intCellStyle;
        private ICellStyle _decimalCellStyle;
        private ICellStyle _redStringCellStyle;
        private ICellStyle _reddecimalCellStyle;
        private ICellStyle _redPersentCellStyle;
        private ICellStyle _blueStringCellStyle;
        private ICellStyle _bluedecimalCellStyle;
        private ICellStyle _bluePersentCellStyle;
        private ICellStyle _numCellStyle;

        public CellStyleHelper(HSSFWorkbook workbook)
        {
            _workbook = workbook;
            IFont fontRed = _workbook.CreateFont();
            fontRed.Color = NPOI.HSSF.Util.HSSFColor.Red.Index;

            IFont fontBlue = _workbook.CreateFont();
            fontBlue.Color = NPOI.HSSF.Util.HSSFColor.Blue.Index;

            _intCellStyle = _workbook.CreateCellStyle();
            _intCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0");

            _numCellStyle = _workbook.CreateCellStyle();
            _intCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0");

            _decimalCellStyle = _workbook.CreateCellStyle();
            _decimalCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0.00");

            _redStringCellStyle = _workbook.CreateCellStyle();
            _redStringCellStyle.SetFont(fontRed);

            _reddecimalCellStyle = _workbook.CreateCellStyle();
            _reddecimalCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0.00");
            _reddecimalCellStyle.SetFont(fontRed);

            _redPersentCellStyle = _workbook.CreateCellStyle();
            _redPersentCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0%");
            _redPersentCellStyle.SetFont(fontRed);

            _blueStringCellStyle = _workbook.CreateCellStyle();
            _blueStringCellStyle.SetFont(fontBlue);

            _bluedecimalCellStyle = _workbook.CreateCellStyle();
            _bluedecimalCellStyle.SetFont(fontBlue);
            _bluedecimalCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0.00");

            _bluePersentCellStyle = _workbook.CreateCellStyle();
            _bluePersentCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0%");
            _bluePersentCellStyle.SetFont(fontBlue);
        }

        public ICellStyle Num
        {
            get { return _numCellStyle; }
        }
        public ICellStyle Int
        {
            get { return _intCellStyle; }
        }
        public ICellStyle Decimal
        {
            get { return _decimalCellStyle; }
        }

        public ICellStyle RedString
        {
            get { return _redStringCellStyle; }
        }

        public ICellStyle Reddecimal
        {

            get { return _reddecimalCellStyle; }
        }

        public ICellStyle RedPersent
        {
            get { return _redPersentCellStyle; }
        }

        public ICellStyle BlueString
        {
            get
            {
                return _blueStringCellStyle;
            }
        }

        public ICellStyle Bluedecimal
        {
            get { return _bluedecimalCellStyle; }
        }

        public ICellStyle BluePersent
        {
            get { return _bluePersentCellStyle; }
        }
    }
}
